package com.mida.dms.knw.service.impl;

import com.alibaba.fastjson.JSONArray;

import com.mida.dms.knw.Result.BaseResult;
import com.mida.dms.knw.entity.*;
import com.mida.dms.knw.entity.vo.DetailCodingSystemVo;
import com.mida.dms.knw.entity.vo.KnwConceptualPage;
import com.mida.dms.knw.entity.vo.KnwConceptualTmpVo;
import com.mida.dms.knw.entity.vo.KnwConceptualVo;
import com.mida.dms.knw.mapper.*;
import com.mida.dms.knw.service.KnwConceptualService;
import com.mida.dms.knw.service.SoidService;
import com.mida.dms.knw.util.CharTransFormUtil;
import com.mida.dms.knw.util.DataSetConstants;
import com.mida.dms.knw.util.ExcelUtil;
import com.mida.dms.knw.util.vo.KnwConceptualUploadFileTitleEnum;
import com.mida.dms.knw.util.vo.UploadFileTitleEnum;
import com.mida.dms.knw.vo.KnwConceptualPageVo;
import com.mida.dms.knw.vo.Page;
import com.mida.dms.knw.vo.PageResultVo;
import com.mida.tool.common.result.ActionResult;
import com.mida.tool.common.result.ListResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedInputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;


/**
 * @author ：wang xiao le
 * @description：TODO
 * @date ：2021/2/22 15:25
 */
@Service
@Slf4j
@Transactional(value = "dtdTxManager", rollbackFor = Exception.class)
public class KnwConceptualServiceImpl extends BaseResult implements KnwConceptualService {

    @Autowired
    private KnwConceptualMapper knwConceptualMapper;

    @Autowired
    private KnwConceptualDomainMapper knwConceptualDomainMapper;

    @Autowired
    private KnwNoumenonMapper knwNoumenonMapper;

    @Autowired
    private KnwConceptualDetailMapper knwConceptualDetailMapper;
    @Autowired
    private KnwCodingConceptualDomainMapper knwCodingConceptualDomainMapper;


    /**
     * ID生成器
     */
    @Autowired
    private SoidService soidService;



    /**
     * 1、新增概念基本信息
     *
     * @param t
     * @return
     */
    @Override
    public ActionResult add(KnwConceptualVo t) {
        if (t.getConceptualSoid() != null) {
            log.info(t.toString() + "不是一个新增，转到update去");
            return update(t);
        }
        log.info("开始新增一个概念" + t.toString());
        StopWatch st = StopWatch.createStarted();
        ActionResult ar = new ActionResult();
        try {
            if (StringUtils.isEmpty(t.getConceptType().toString())) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念类型不能为空");
                return ar;
            }

            if (StringUtils.isEmpty(t.getConceptFsn())) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念FSN不能为空");
                return ar;
            }

            int count = knwConceptualDetailMapper.countFsn(t.getConceptFsn());
            if (count > 0) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念FSN已存在");
                return ar;
            }
            t.setPyCode(CharTransFormUtil.toPinyinSimple(t.getConceptFsn()));
            t.setWbCode(CharTransFormUtil.toWubi(t.getConceptFsn()));
//            Long seq = oIDGanerator.getSOID();
            Long seq = soidService.getSoid();

            t.setConceptualSoid(seq);
            t.setCreateDate(new Date());
            t.setIsDelete(0L);
            KnwConceptual knwConceptual = setKnwConceptual(t);
            //1.添加概念基本信息
            knwConceptualMapper.insert(knwConceptual);
            soidService.insertOid(seq,1);
//            String oid = oIDGanerator.getOID(0);
//            DtOid dtOid = new DtOid();
//            dtOid.setOid(oid);
//            dtOid.setSoid(seq);
//            dtOidMapper.insert(dtOid);

            //2.添加概念描述
            KnwConceptualDetail kcDetail = new KnwConceptualDetail();
//            kcDetail.setConceptualDetailSoid(oIDGanerator.getSOID());
            kcDetail.setConceptualDetailSoid(soidService.getSoid());
            kcDetail.setConceptualDetailName(t.getConceptFsn());
            kcDetail.setConceptualSoid(seq);
            kcDetail.setIsPreferred(1L);
            kcDetail.setLanguageSoid(DataSetConstants.CHINIES);
            kcDetail.setConceptualDetailType(DataSetConstants.FSN);
            kcDetail.setStatus(t.getStatus());
            kcDetail.setIsDelete(0L);
            kcDetail.setPyCode(CharTransFormUtil.toPinyinSimple(t.getConceptFsn()));
            kcDetail.setWbCode(CharTransFormUtil.toWubi(t.getConceptFsn()));
            knwConceptualDetailMapper.insert(kcDetail);

            //添加概念域
            if (t.getIsConceptualDomain() != null && t.getIsConceptualDomain().equals(1L)) {
                KnwConceptualDomain kCDomain = new KnwConceptualDomain();
//                kCDomain.setDomainSoid(oIDGanerator.getSOID());
                kCDomain.setDomainSoid(soidService.getSoid());
                kCDomain.setConceptualSoid(seq);
                String domainName = t.getConceptFsn() + "概念域";
                kCDomain.setDomainName(domainName);
                kCDomain.setPyCode(CharTransFormUtil.toPinyinSimple(domainName));
                kCDomain.setWbCode(CharTransFormUtil.toWubi(domainName));
                kCDomain.setStatus(t.getStatus());

                kCDomain.setConceptDomainTypeSoid(t.getConceptType());
                knwConceptualDomainMapper.insert(kCDomain);

            }
            buildActionSuccess(ar);

        } catch (Exception e) {
            log.error("新增概念发送异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            buildActionWarn(ar, "新增概念发送异常");
        } finally {
            st.stop();
            log.info("本次新增耗时:" + st.getTime() + "ms");
        }
        return ar;
    }

    private KnwConceptual setKnwConceptual(KnwConceptualVo t) {
        KnwConceptual knwConceptual = new KnwConceptual();
        knwConceptual.setConceptualSoid(t.getConceptualSoid());
        knwConceptual.setConceptType(t.getConceptType());
        knwConceptual.setPyCode(t.getPyCode());
        knwConceptual.setWbCode(t.getWbCode());
        knwConceptual.setCreateDate(t.getCreateDate());

        knwConceptual.setUpdateDate(t.getUpdateDate());
        knwConceptual.setUpdateUser(t.getUpdateUser());
        knwConceptual.setStatus(t.getStatus());
        knwConceptual.setIsDelete(t.getIsDelete());
        return knwConceptual;
    }

    /**
     * /2、 更新概念
     *
     * @param t
     * @return
     */
    @Override
    public ActionResult update(KnwConceptualVo t) {
        log.info("开始更新一个概念" + t.toString());
        StopWatch st = StopWatch.createStarted();
        ActionResult ar = new ActionResult();
        try {
            if (StringUtils.isEmpty(t.getConceptualSoid().toString())) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念Soid不能为空");
                return ar;
            }
            if (StringUtils.isEmpty(t.getConceptType().toString())) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念类型不能为空");
                return ar;
            }

            List<KnwConceptualDomain> knwConceptualDomains = knwConceptualDomainMapper.selectByConceptualsoid(t.getConceptualSoid());
            if (knwConceptualDomains.size() != 0 && t.getIsConceptualDomain() == 0) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("启用状态下，不能将是改为否");
                return ar;
            }

            t.setUpdateDate(new Date());
            KnwConceptual knwConceptual = setKnwConceptual(t);
            //1.更新概念基本信息
            knwConceptualMapper.updateByPrimaryKeySelective(knwConceptual);

            //2.修改概念域
            if (t.getIsConceptualDomain() != null && t.getIsConceptualDomain().equals(1L)) {
                if (knwConceptualDomains.size() != 0 && knwConceptualDomains.get(0) != null) {//原先有概念域，修改概念域
                    KnwConceptualDomain kCDomain = knwConceptualDomains.get(0);
                    kCDomain.setStatus(t.getStatus());
                    kCDomain.setUpdateDate(new Date());
                    kCDomain.setConceptDomainTypeSoid(t.getConceptType());
                    knwConceptualDomainMapper.updateByPrimaryKeySelective(kCDomain);
                } else {
                    KnwConceptualDomain kCDomain = new KnwConceptualDomain();
//                    kCDomain.setDomainSoid(oIDGanerator.getSOID());
                    kCDomain.setDomainSoid(soidService.getSoid());
                    kCDomain.setConceptualSoid(t.getConceptualSoid());
                    String domainName = t.getConceptFsn() + "概念域";
                    kCDomain.setDomainName(domainName);
                    kCDomain.setPyCode(CharTransFormUtil.toPinyinSimple(domainName));
                    kCDomain.setWbCode(CharTransFormUtil.toWubi(domainName));
                    if (t.getStatus()==null) {
                        throw new  RuntimeException("概念域状态不能为空");
                    }
                    kCDomain.setStatus(t.getStatus());
                    kCDomain.setCreateDate(new Date());
                    kCDomain.setIsDelete(0L);
                    kCDomain.setConceptDomainTypeSoid(t.getConceptType());
                    knwConceptualDomainMapper.insertSelective(kCDomain);

                }
            }


            buildActionSuccess(ar);
        } catch (Exception e) {
            log.error("更新概念发送异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            buildActionWarn(ar, "更新概念发送异常");
        } finally {
            st.stop();
            log.info("本次新增耗时:" + st.getTime() + "ms");
        }
        return ar;
    }

    /**
     * /3、 删除概念
     *
     * @param soid
     * @return
     */
    @Override
    public ActionResult delete(long soid) {
        log.info("开始删除一个概念" + soid);
        StopWatch st = StopWatch.createStarted();
        ActionResult ar = new ActionResult();
        try {
            KnwConceptual knwConceptual = knwConceptualMapper.selectByPrimaryKey(soid);
            if (knwConceptual != null) {
                if (knwConceptual.getStatus() != null && knwConceptual.getStatus().equals(DataSetConstants.OPENSTATUS)) {
                    ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                    ar.setMessage("启用状态下不可删除");
                    return ar;
                }
            }

            knwConceptualMapper.deleteByPrimaryKey(soid); //删除概念基本信息
            List<KnwConceptualDomain> kcd = knwConceptualDomainMapper.selectByConceptualsoid(soid);
            if (kcd.size() != 0) {

                Long domainSoid = kcd.get(0).getDomainSoid();
                knwCodingConceptualDomainMapper.deleteByDomainSoid(domainSoid);//删除绑定的编码体系
                knwConceptualDomainMapper.deleteByConsuptSoid(soid);//删除所在域
            }
            knwConceptualDetailMapper.deleteByConsuptSoid(soid);//删除概念描述

            buildActionSuccess(ar);
        } catch (Exception e) {
            log.error("删除概念发送异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            buildActionWarn(ar, "删除概念发送异常");
        } finally {
            st.stop();
            log.info("本次删除耗时:" + st.getTime() + "ms");
        }
        return ar;
    }

    /**
     * 4、获取概念
     *
     * @param soid
     * @return
     */
    @Override
    public ListResult<KnwConceptualVo> get(long soid) {
        log.info("开始获取一个概念" + soid);
        StopWatch st = StopWatch.createStarted();
        ListResult<KnwConceptualVo> lr = new ListResult<KnwConceptualVo>();
        try {
            KnwConceptualVo ns = knwConceptualMapper.selectByConceptSoid(soid);
            buildListSuccess(lr, ns);
        } catch (Exception e) {
            log.error("查命名体系发送异常", e);
            buildListWarn(lr, "查命名体系发送异常");
        } finally {
            st.stop();
            log.info("本次查询耗时:" + st.getTime() + "ms");
        }
        return lr;
    }

    /**
     * 5、概念分页查询
     *
     * @param vo
     * @return
     */
    @Override
    public ListResult<PageResultVo<KnwConceptualVo>> findPage(KnwConceptualPageVo vo) {
        log.info("开始分页查询,查询条件:" + vo.toString());
        ListResult result = new ListResult();
        PageResultVo pvo = new PageResultVo();
        Page page = new Page(vo.getCurrentPage(), vo.getPageSize());
        pvo.setPage(page);
        StopWatch st = StopWatch.createStarted();

        List<KnwConceptualVo> list = null;
        try {
            String searChData = vo.getSearChData();
            if (ObjectUtils.isNotEmpty(searChData)) {
                searChData=searChData.trim().toUpperCase();
            }
            KnwConceptualPage npage = new KnwConceptualPage(vo.getCurrentPage(), vo.getPageSize(), searChData, vo.getConceptType());
            int count = knwConceptualMapper.findPageCount(npage);
            if (count != 0) {
                page.setTotalCount(count);
                list = knwConceptualMapper.findPageVo(npage);
            } else {
                pvo.setPage(null);
                pvo.setList(null);
            }
            pvo.setList(list);
            buildListSuccess(result, pvo);
        } catch (Exception e) {
            list = new ArrayList<KnwConceptualVo>(0);
            pvo.setList(list);
            log.error("分页查编码体系发送异常", e);
            buildListWarn(result, "分页查编码体系发送异常");
        } finally {
            st.stop();
            log.info("本次分页查询耗时:" + st.getTime() + "ms");
        }
        return result;


    }

    /**
     * 6、查询全部概念
     *
     * @param
     * @return
     */
    @Override
    public ListResult<List<KnwConceptualVo>> findAll(String searChData, Long conceptType) {
        log.info("开始查询全部概念,查询条件:");
        StopWatch st = StopWatch.createStarted();
        ListResult result = new ListResult();
        List<KnwConceptualVo> list = null;
        try {

            HashMap<String, Object> map = new HashMap<>();
            if (StringUtils.isNotEmpty(searChData)) {
                map.put("searChData", searChData.trim().toUpperCase());

            }
            if (conceptType != null) {

                map.put("conceptType", conceptType);
            }

            list = knwConceptualMapper.findAll(map);
            buildListSuccess(result, list);
        } catch (Exception e) {
            list = new ArrayList<KnwConceptualVo>(0);
            log.error("查询全部概念发送异常", e);
            buildListWarn(result, "查询全部概念发送异常");
        } finally {
            st.stop();
            log.info("本次查询全部命名系统查询耗时:" + st.getTime() + "ms");

        }
        return result;
    }

    /**
     * 校验概念FSN重复性
     *
     * @param name 概念FSN
     * @return
     */
    @Override
    public ActionResult checkName(String name) {
        log.info("开始检查是否重名" + name);
        StopWatch st = StopWatch.createStarted();
        ActionResult ar = new ActionResult();
        try {
            if (StringUtils.isEmpty(name)) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念FSN不能为空");
                return ar;
            }

            int count = knwConceptualDetailMapper.countFsn(name);
            if (count > 0) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念FSN已存在");
                return ar;
            }
            buildActionSuccess(ar);
        } catch (Exception e) {
            log.error("检查概念发送异常", e);
            buildActionWarn(ar, "检查概念发送异常");
        } finally {
            st.stop();
            log.info("本次检查耗时:" + st.getTime() + "ms");
        }
        return ar;
    }

    /**
     * 更新概念状态
     *
     * @param status
     * @param conceptualSoid
     * @return
     */
    @Override
    public ActionResult updateStatus(Long status, Long conceptualSoid) {
        log.info("开始更新概念状态" + status);
        StopWatch st = StopWatch.createStarted();
        ActionResult ar = new ActionResult();
        try {
            if (status==null) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念状态不能为空");
                return ar;
            }
            if (conceptualSoid==null) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念soid不能为空");
                return ar;
            }
            List<KnwNoumenon> list = knwNoumenonMapper.selectByConceptualSoid(conceptualSoid);
            if (list.size() != 0 &&  DataSetConstants.CLOSESTATUS.equals(status)) {
                ar.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                ar.setMessage("概念已被本体引用，不能停用");
                return ar;
            }
            KnwConceptual knwConceptual = new KnwConceptual();
            knwConceptual.setStatus(status);
            knwConceptual.setConceptualSoid(conceptualSoid);
            knwConceptualMapper.updateByPrimaryKeySelective(knwConceptual);

            //概念域的状态与概念是联动的
            List<KnwConceptualDomain> knwConceptualDomains = knwConceptualDomainMapper.selectByConceptualsoid(conceptualSoid);
            if (knwConceptualDomains.size()!=0) {
                KnwConceptualDomain knwConceptualDomain = knwConceptualDomains.get(0);
                knwConceptualDomain.setStatus(status);
                knwConceptualDomainMapper.updateByPrimaryKeySelective(knwConceptualDomain);
            }

            buildActionSuccess(ar);
        } catch (Exception e) {
            log.error("更新概念状态异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            buildActionWarn(ar, "更新概念状态异常");
        } finally {
            st.stop();
            log.info("本次检查耗时:" + st.getTime() + "ms");
        }
        return ar;
    }

    /**
     * 值集批量上传处理
     *
     * @param file
     * @return
     */
    @Override
    public ActionResult uploadFile(MultipartFile file) throws Exception {

        ActionResult actionResult = new ActionResult();
        BufferedInputStream bufferedInput = null;
        JSONArray jsonArray = null;

        if (file.isEmpty()) {
            log.error("文件不存在！");
            actionResult.setMessage("文件不存在！");
            actionResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            return actionResult;
        }

        String fileName = file.getOriginalFilename();
        if (StringUtils.isNotEmpty(fileName)
                && !"xlsx".equals(fileName.substring(fileName.indexOf(".") + 1))) {
            log.error("文件扩展名不正确！");
            actionResult.setMessage("文件扩展名不正确！");
            actionResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            return actionResult;
        }

        bufferedInput = new BufferedInputStream(file.getInputStream());
        Map<String, Object> map = new HashMap();
        List<KnwConceptualTmpVo> list = new ArrayList<KnwConceptualTmpVo>();
        if (bufferedInput != null) {
            jsonArray = ExcelUtil.getValues(bufferedInput);
            if (jsonArray != null && jsonArray.size() > 0) {
                for (int i = 0; i < jsonArray.size(); i++) {
                    map = (Map) jsonArray.get(i);
                    KnwConceptualTmpVo knwConceptualTmpVo;
                    if (map != null && map.size() > 0) {
                        knwConceptualTmpVo = new KnwConceptualTmpVo(map);
                        list.add(knwConceptualTmpVo);
                    }
                }
            }
        }

        // 数据校验
        if (list.size() > 0) {
            String errorMsg = checkData(list);
            if (StringUtils.isNotEmpty(errorMsg)) {
                actionResult.setMessage(errorMsg);
                actionResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
                return actionResult;
            }

            addknwConceptual(list);

        }

        buildActionSuccess(actionResult);
        return actionResult;
    }

    /**
     * 验证
     * @param list
     * @return
     */
    private String checkData(List<KnwConceptualTmpVo> list) throws Exception {

        Map<String, Object> mapTmp = new HashMap<String, Object>();
        String errorMsg =  "";

//        List<String> listStr = knwConceptualDetailMapper.getConceptualDetailNames();
//        Map<String, Object> totalMap = new HashMap<>();
//        if (listStr != null && listStr.size() > 0) {
//            AtomicInteger i = new AtomicInteger();
//            totalMap = listStr.stream().collect(
//                    Collectors.toMap(str -> listStr.get(i.getAndIncrement()),
//                            str -> ""));
//        }
//
//        Map<String, Object> mapParm = new HashMap<String, Object>();
//        mapParm.put("identifier","DHUCVKNW0012");
//        List<DetailCodingSystemDto> listDetailCodingSystemVo  = detailCodingSystemMapper.getDetailCodingList(mapParm);
//
//        Map<String, Object> map = new HashMap<>();
//        if (listDetailCodingSystemVo != null && listDetailCodingSystemVo.size() > 0) {
//            for (DetailCodingSystemDto dcs : listDetailCodingSystemVo) {
//                map.put(dcs.getDataSetSoid().toString(),"");
//            }
//        }
//
//
//
//        for (int i = 0; i < list.size(); i++) {
//            KnwConceptualTmpVo kc =  list.get(i);
//
//            if (StringUtils.isEmpty(kc.getConceptFsn())) {
//                errorMsg = KnwConceptualUploadFileTitleEnum.CONCEPTUAL_DETAIL_NAME.getPosition()
//                        + (i + 2) + "概念FSN为空";
//                return errorMsg;
//            }
//
//            if (kc.getConceptType() == null) {
//                errorMsg = KnwConceptualUploadFileTitleEnum.CONCEPT_TYPE.getPosition()
//                        + (i + 2) + "概念分类为空";
//                return errorMsg;
//            } else {
//                if (map.get(kc.getConceptType()) == null) {
//                    errorMsg = KnwConceptualUploadFileTitleEnum.CONCEPT_TYPE.getPosition()
//                            + (i + 2) + "概念分类数据库不存在";
//                    return errorMsg;
//                }
//            }
//
//            if (StringUtils.isEmpty(kc.getStatus())) {
//                errorMsg = KnwConceptualUploadFileTitleEnum.STATUS.getPosition()
//                        + (i + 2) + "状态为空";
//                return errorMsg;
//            } else {
//                if (!"149".equals(kc.getStatus())) {
//                    errorMsg = UploadFileTitleEnum.STATUS.getPosition()
//                            + (i + 2) + "单元格的状态不正确";
//                    return errorMsg;
//                }
//            }
//
//            if (totalMap.get(kc.getConceptFsn()) != null) {
//                errorMsg = KnwConceptualUploadFileTitleEnum.CONCEPTUAL_DETAIL_NAME.getPosition()
//                        + (i + 2) + "概念FSN数据库存在";
//                return errorMsg;
//            }
//
//            // excel中重复
//            if (mapTmp.get(kc.getConceptFsn()) == null) {
//                mapTmp.put(kc.getConceptFsn(),"");
//            } else {
//                errorMsg = KnwConceptualUploadFileTitleEnum.CONCEPTUAL_DETAIL_NAME.getPosition()
//                        + (i + 2) + "概念FS在Nexcel中重复";
//                return errorMsg;
//            }
//        }

        return errorMsg;
    }

    /**
     * 保存数据
     */
    private void addknwConceptual (List<KnwConceptualTmpVo> list) throws Exception {

        for (KnwConceptualTmpVo k : list) {
//            Long seq = oIDGanerator.getSOID();
            Long seq = soidService.getSoid();
            KnwConceptual knwConceptual = new KnwConceptual();
            knwConceptual.setConceptualSoid(seq);
            knwConceptual.setConceptType(Long.valueOf(k.getConceptType()));
            knwConceptual.setPyCode(CharTransFormUtil.toPinyinSimple(k.getConceptFsn()));
            knwConceptual.setWbCode(CharTransFormUtil.toWubi(k.getConceptFsn()));
            knwConceptual.setCreateDate(new Date());
            knwConceptual.setStatus(Long.valueOf(k.getStatus()));
            knwConceptual.setIsDelete(0L);

            //1.添加概念基本信息
            knwConceptualMapper.insert(knwConceptual);
            soidService.insertOid(seq,1);
//            String oid = oIDGanerator.getOID(0);
//            DtOid dtOid = new DtOid();
//            dtOid.setOid(oid);
//            dtOid.setSoid(seq);
//            dtOidMapper.insert(dtOid);

            //2.添加概念描述
            KnwConceptualDetail kcDetail = new KnwConceptualDetail();
//            kcDetail.setConceptualDetailSoid(oIDGanerator.getSOID());
            kcDetail.setConceptualDetailSoid(soidService.getSoid());
            kcDetail.setConceptualDetailName(k.getConceptFsn());
            kcDetail.setConceptualSoid(seq);
            kcDetail.setIsPreferred(1L);
            kcDetail.setLanguageSoid(DataSetConstants.CHINIES);
            kcDetail.setConceptualDetailType(DataSetConstants.FSN);
            kcDetail.setStatus(Long.valueOf(k.getStatus()));
            kcDetail.setIsDelete(0L);
            kcDetail.setPyCode(CharTransFormUtil.toPinyinSimple(k.getConceptFsn()));
            kcDetail.setWbCode(CharTransFormUtil.toWubi(k.getConceptFsn()));
            knwConceptualDetailMapper.insert(kcDetail);
        }
    }
}
